package com.xiongjie.util;

import io.vertx.core.AsyncResult;
import io.vertx.core.Future;
import io.vertx.core.Handler;
import io.vertx.core.Vertx;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.web.templ.pebble.PebbleTemplateEngine;

public class PebbleUtil {

    public static void render(Vertx vertx, String templateName, JsonObject json, Handler<AsyncResult<String>> resultHandler){
        PebbleTemplateEngine engine=PebbleTemplateEngine.create(vertx);

        engine.render(json,templateName,res -> {
            try {
                String html = res.result().toString();
                resultHandler.handle(Future.succeededFuture(html));
            }catch (Exception e){
                e.printStackTrace();
            }
        });
    }

}
